#!/bin/bash
cd /root/my_shell/hosts_update/hosts_update
wget  https://gitee.com/developerzzf/tv/raw/master/best_ip.txt

new_cf_ip=`cat best_ip.txt | grep cloudflare | cut -d ":" -f 2`
new_cft_ip=`cat best_ip.txt | grep cloudfront | cut -d ":" -f 2`
old_cf_ip=`cat old_ip.txt | grep cloudflare | cut -d ":" -f 2`
old_cft_ip=`cat old_ip.txt | grep cloudfront | cut -d ":" -f 2`

if [ $old_cf_ip = $new_cf_ip ] || [ $old_cft_ip = $new_cft_ip ]; then
        echo "warning! the old ip as same as new ip!"
else
        sed -i "s/$old_cf_ip/$new_cf_ip/g"  /etc/hosts
        sed -i "s/$old_cf_ip/$new_cf_ip/g"  /etc/hosts
        service dnsmasq restart
        cat best_ip.txt > old_ip.txt
fi

rm -rf best_ip.txt
